package com.minelx.datamicroscope.querylanguage.data.sql;

import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.ast.statement.SQLTableSource;

public interface AliasedTablesFulfil {
	void fulfil(AliasedTablesBuilder aliasedTablesBuilder);

	static AliasedTablesFulfil create(SQLTableSource fromTable, SQLSelectQueryBlock firstQueryBlock) {
		if (fromTable instanceof SQLExprTableSource) {
			return new ContentAliasedTablesFulfill((SQLExprTableSource) fromTable);
		} else if (fromTable instanceof SQLJoinTableSource) {
			return new JoinAliasedTablesFulfil(firstQueryBlock, (SQLJoinTableSource) fromTable);
		} else {
			throw new UnsupportedOperationException("FromTableExpr.createFromTableExpr() encountered an unexpected type of SQLTableSource: " + fromTable.getClass());
		}
	}
}
